package cn.itcast.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RuntimeMonitorAspect {

    @Around("execution(* cn.itcast.aop.synthesize.Target.save())")
    public Object around(ProceedingJoinPoint pjp)throws Throwable{
        String className = pjp.getSignature().getDeclaringTypeName();
        String methodName = pjp.getSignature().getName();

        long starTime = System.currentTimeMillis();
        Object result = pjp.proceed(pjp.getArgs());
        long endTime = System.currentTimeMillis();
        System.out.println(className+":"+methodName+"执行花费了"+(endTime-starTime)+"毫秒");
        return result;
    }
}
